import request from './index'

export const productAPI = {
  // 获取产品列表
  getList: (params) => {
    return request.get('/products', { params })
  },

  // 获取产品详情
  getDetail: (id) => {
    return request.get(`/products/${id}`)
  },

  // 创建产品
  create: (data) => {
    return request.post('/products', data)
  },

  // 更新产品
  update: (id, data) => {
    return request.put(`/products/${id}`, data)
  },

  // 删除产品
  delete: (id) => {
    return request.delete(`/products/${id}`)
  },

  // 上架产品
  online: (id) => {
    return request.put(`/products/${id}/online`)
  },

  // 下架产品
  offline: (id) => {
    return request.put(`/products/${id}/offline`)
  },

  // 上传产品图片
  uploadImage: (formData) => {
    return request.post('/products/upload', formData, {
      headers: {
        'Content-Type': 'multipart/form-data'
      }
    })
  },

  // 批量上传产品图片
  uploadImages: (formData) => {
    return request.post('/products/upload/batch', formData, {
      headers: {
        'Content-Type': 'multipart/form-data'
      }
    })
  },

  // 获取产品统计
  getStats: () => {
    return request.get('/admin/products/stats')
  },

  // 获取产品分类
  getCategories: () => {
    return request.get('/products/categories')
  },

  // 批量更新产品状态
  batchUpdateStatus: (ids, status) => {
    return request.put('/products/batch-status', { ids, status })
  }
}